<?php
namespace Android\Controller;

class ClassController extends BaseController {


    /**
     * 获取指定老师管理的班级列表
     *
     */
    public function getClassList() {

        $teacher_id = I ('request.teacher_id','');
        if (empty($teacher_id))
            $this->out($this->fail,'Empty teacher_id');

        $classIdArr = D ('ClassManager')->getClassIdsByTid($teacher_id);
        if (empty($classIdArr))
            $this->out($this->fail, '没有可管理班级');

        // 获取班级信息
        $classArr = D ('Class')->getClassArrByIdArr($classIdArr);
        if (empty($classIdArr))
            $this->out($this->fail, '没有课管理班级');

        // 获取班级人数、班长团支书信息
        $Student = D ('Student');
        foreach  ($classArr as $k=>$v) {

            $classArr[$k]['count'] = $Student->getScountByCid($v['id']);
            $classArr[$k]['monitor'] = $Student->getStudentById($v['monitor'],"student_id,name,photo,sex,telphone");
            $classArr[$k]['tzs'] = $Student->getStudentById($v['tzs'],'student_id,name,photo,sex,telphone');

        }

        $this->out($this->success,'Success',$classArr);

    }


    /**
     * 获取指定班级的所有学生
     *
     */
    public function getClassStudent() {

        $class_id = I ('request.class_id','');
        if (empty($class_id))
            $this->out($this->fail,'Empty class_id');

        $studentArr = D ('Student')->getStudentByCid($class_id,'id,student_id,name,sex,photo,telphone');
        if (empty($studentArr))
            $this->out($this->fail, '当前班级没有任何学生');

        $Class = D ('Class');
        foreach ($studentArr as $k=>$v) {
            $studentArr[$k]['class_name'] = $Class->getFullClassName($class_id);
        }

        $this->out($this->success,'Success',$studentArr);
    }

}